﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using TableDataSet;

namespace Util
{
    public class studentDetailDA
    {
        static OleDbConnection connection;
        private OleDbDataAdapter adapter;

        public studentDetailDS searchAllStudent()
        {
            try
            {
                using(connection = new DBUtil().getOleConnection())
                {
                    adapter = new OleDbDataAdapter();
                    adapter.SelectCommand = connection.CreateCommand();
                    adapter.SelectCommand.CommandText = "select * from student_detail";

                    studentDetailDS student = new studentDetailDS();
                    adapter.Fill(student, "student_detail");

                    return student;
                }
            }
            catch(Exception e)
            {

            }
            return null;
        }

        public studentDetailDS searchStudentByClass(int classID)
        {
            try
            {
                using (connection = new DBUtil().getOleConnection())
                {
                    adapter = new OleDbDataAdapter();
                    adapter.SelectCommand = connection.CreateCommand();
                    adapter.SelectCommand.CommandText = "select * from student_detail where class_id = " + classID;

                    studentDetailDS student = new studentDetailDS();
                    adapter.Fill(student, "student_detail");

                    return student;
                }
            }
            catch (Exception e)
            {
                
            }
            return null;
        } 
    }
}
